<!DOCTYPE html>
<html lang='zh-CN'>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
    <title>商场订单表</title>
    <link rel="icon" href="favicon.ico" type="image/ico">
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/materialdesignicons.min.css" rel="stylesheet">
    <link href="css/animate.css" rel="stylesheet">
    <link href="css/style.min.css" rel="stylesheet">
    <link href="js/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">

</head>
<body>
<div class="container-fluid p-t-15">

    <div class="row">
        <div class="col-lg-12">
            <div class="card">
                <div class="card-header">
                    <h4>商场订单记录</h4>
                    <div id="toolbar" class="toolbar-btn-action">
                        <form class="form-inline" method="post" id="searchForm" action="/remote/getExcel">
                            <div class="form-group">
                                <label>支付时间:</label>
                                <input type="text" class="form-control js-datepicker" data-date-format="yyyy-mm-dd" name="startTime" placeholder="开始时间" style="width:120px;"> -
                                <input type="text" class="form-control js-datepicker" data-date-format="yyyy-mm-dd" name="endTime" placeholder="结束时间" style="width:120px;">
                            </div>
                            <div class="form-group">
                                <label>会员账号:</label>
                                <input type="text" class="form-control" name="memberId">
                            </div>
                            <div class="form-group">
                                <label>订单号:</label>
                                <input type="text" class="form-control" name="outTradeNo">
                            </div>
                            <div class="form-group">
                                <label>订单状态:</label>
                                <select name="orderState" class="form-control">
                                    <option value="">全部</option>
                                    <option value="0">待付款</option>
                                    <option value="1">待发货</option>
                                    <option value="2">待取货</option>
                                    <option value="3">已完成</option>
                                </select>
                            </div>
                            <div class="form-group">
                                <button class="btn btn-info btn_query btn-round"  type="button" id="searchFormBtn">查询</button>
                            </div>
                            <div class="form-group">
                                <button class="btn btn-purple btn_query btn-round" type="button" id="watchBtn">商品详情</button>
                            </div>
                            <div class="form-group">
                                <button class="btn btn-success btn_query btn-round" type="button" id="merchantShipmentBtn">商家发货</button>
                            </div>
                            <div class="form-group">
                                <button class="btn btn-secondary btn_query btn-round" type="button" id="generate-excel">导出商品数据</button>
                            </div>
                            <div class="form-group">
                                <button class="btn btn-pink btn_query btn-round" type="button" id="generate-invoice">小票打印</button>
                            </div>
                        </form>
                    </div>
                </div>
                <div class="card-body">
                    <table id="list_data"></table>
                </div>
            </div>
        </div>
    </div>

    <!--  商品详细模态框 -->
    <div class="modal fade" id="merchantShipmentModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabels">
        <div class="modal-dialog" role="document" style="width: 60%;">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="ProductInformation">商品内容</h4>
                </div>
                <div class="modal-body" id="commodityMessage"></div>
            </div>
        </div>
    </div>

    <!--  查看详细模态框 -->
    <div class="modal fade" id="seeDetailsModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabels">
        <div class="modal-dialog" role="document" style="width: 60%;">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="seeDetails">商品内容</h4>
                </div>
                <div class="modal-body" id="seeDetailsMessage"></div>
            </div>
        </div>
    </div>

    <!--  商品发货物流模态框 -->
    <div class="modal fade" id="ShippedModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="exampleModalLabel">物流详细</h4>
                </div>
                <div class="modal-body">
                    <form id="ShippedForm" method="post" action="/remote/deliverGoods" enctype="multipart/form-data" >
                        <input type="hidden" class="form-control" id="id" name="id" required>
                        <div class="row">
                            <div class="col-xs-12">
                                <label class="control-label">物流公司：</label>
                                <select name="logisticsCompany" class="form-control" placeholder="请输入价格">
                                    <option value="">选择物流公司：</option>
                                    <option value="顺丰速运">顺丰速运</option>
                                    <option value="邮政快递">邮政快递</option>
                                    <option value="中通快递">中通快递</option>
                                    <option value="圆通速递">圆通速递</option>
                                    <option value="申通快递">申通快递</option>
                                    <option value="百世快递">百世快递</option>
                                    <option value="韵达快递">韵达快递</option>
                                    <option value="京东快递">京东快递</option>
                                    <option value="德邦物流">德邦物流</option>
                                    <option value="国通快递">国通快递</option>
                                    <option value="快捷速递">快捷速递</option>
                                    <option value="速尔快递">速尔快递</option>
                                    <option value="能达快递">能达快递</option>
                                </select>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-xs-12">
                                <label for="logisticsNo" class="control-label">物流单号：</label>
                                <!--限制数字为20-->
                                <input type="number" class="form-control" id="logisticsNo" name="logisticsNo" oninput="if(value.length>10)value=value.slice(0,20)" required>
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                            <button type="button" id="subtn" class="btn btn-primary">保存</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/bootstrap-table/bootstrap-table.js"></script>
<script type="text/javascript" src="js/bootstrap-table/bootstrap-table-zh-CN.min.js"></script>
<script type="text/javascript" src="js/zero2one/zero2one.version.js"></script>
<script type="text/javascript" src="js/zero2one/zero2one.core.js"></script>
<!-- bootstrap表单验证插件 -->
<script type="text/javascript" src="js/bootstrap-validator-master/dist/validator.js"></script>
<!-- jquery-form表单提交插件 -->
<script type="text/javascript" src="js/jquery-form/jquery.form.js"></script>
<!-- bootstrap弹出框插件 -->
<script type="text/javascript" src="js/jquery.bootstrap.min.js"></script>
<!-- 表单填充插件 -->
<script type="text/javascript" src="js/jquery-form/jquery.formloader.js"></script>
<!--日期选择插件-->
<script src="js/bootstrap-datepicker/bootstrap-datepicker.min.js"></script>
<script src="js/bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN.min.js"></script>
<script type="text/javascript" src="js/main.min.js"></script>


<script type="text/javascript">


        //设置表头
        var columns = [
            {checkbox: true},
            {field: 'outTradeNo',title: '订单号'},
            {field: 'storeId',title: '商店账号',visible: false},
            {field: 'storeName',title: '商店名称'},
            {field: 'orderAmount',title: '订单金额'},
            {field: 'totalPrice',title: '应付金额'},
            {field: 'goodItems',title: '--------------------------商品-------------------------',formatter: function (value, row, index) {
                    var jsonObj =  JSON.parse(value);
                    var content='';
                    for (let i = 0; i <jsonObj.length ; i++) {
                        content+=
                            '<label style="font-size: small">商品（'+(i+1)+'）标题：</label><label style="font-size: small">'+jsonObj[i].title+'</label>'
                            +'<label style="font-size: small">,购买数：</label><label style="font-size: small">'+jsonObj[i].count+'</label>'
                            +'<label style="font-size: small">,价格：</label><label style="font-size: small">'+jsonObj[i].price+'</label>'
                            +'<label style="font-size: small">元,规格：</label><label style="font-size: small">'+jsonObj[i].skuAttr+'</label>'
                            +'<br>'
                    }
                    return content;
                }},
            {field: 'createTime',title: '订单创建时间',formatter: function (value) {
                    return zero2one.dateFormat(value, 'Y-m-d H:i:s')
                }},
            {field: 'orderState',title: '订单状态',formatter: function (value, row, index) {
                    if (value=='0') {
                        return  "<button class=\"btn btn-warning btn-sm\">待付款</button>";
                    }else if(value=='1'){
                        return  "<button class=\"btn btn-warning btn-sm\">待发货</button>";
                    }else if(value=='2'){
                        return  "<button class=\"btn btn-warning btn-sm\">待取货</button>";
                    }else if(value=='3'){
                        return  "<button class=\"btn btn-success btn-sm\">已完成</button>";
                    }else if(value=='4'){
                        return  "<button class=\"btn btn-danger btn-sm\">超时关闭</button>";
                    }else if(value=='5'){
                        return  "<button class=\"btn btn-primary btn-sm\">取消订单</button>";
                    }else if(value=='6'){
                        return  "<button class=\"btn btn-warning btn-sm\">退款中</button>";
                    }else if(value=='7'){
                        return  "<button class=\"btn btn-success btn-sm\">退款成功</button>";
                    }else if(value=='8'){
                        return  "<button class=\"btn btn-danger btn-sm\">退款失败</button>";
                    }else if(value=='9'){
                        return  "<button class=\"btn btn-danger btn-sm\">关闭交易</button>";
                    }
                }},
            {field: 'orderFreight',title: '运费金额'},
            {field: 'hasSaleAfter',title: '订单售后',formatter:function (value,row) {
                    var OrderId=row.id+"";//字段太长，使用切割方式传数据
                    var OrderId1=OrderId.substring(0,9);
                    var OrderId2=OrderId.substring(9,19);
                    if (value==0){
                       return "无";
                    }else if(value==1){
                        return "<div class=\"form-group\">\n" +
                            "    <button class=\"btn btn-brown btn_query btn-round\" type=\"button\" onclick=\"seeDetails("+OrderId1+","+OrderId2+")\">查看详细</button>\n" +
                            "</div>";
                    }
                }},
            {field: 'address',title: '--------------------收获地址-------------------',formatter: function (value, row, index) {
                    var bToObj=JSON.parse(value);//json数据组解析
                    return "姓名："+bToObj.receiverName+' \n '+"电话："+bToObj.receivePhone+' \n '+"地址："+bToObj.provinceName+bToObj.cityName+bToObj.regionName +bToObj.streetAddr;
                }},
            {field: 'payType',title: '支付渠道',formatter: function (value, row, index) {
                    if (value=='pearl') {
                        return "珍珠";
                    }else if(value=='alipay'){
                        return  "支付宝";
                    }else if(value=='wxpay'){
                        return "微信";
                    }
                }},
            {field: 'payTime',title: '支付时间', formatter: function (value) {
                    if (value==null){
                        return  "未支付";
                    }
                    return zero2one.dateFormat(value, 'Y-m-d H:i:s')
                }},
            {field: 'deliveryTime',title: '商品发货时间', formatter: function (value) {
                    if (value==null){
                        return  "未发货";
                    }
                    return zero2one.dateFormat(value, 'Y-m-d H:i:s')
                }},
            {field: 'confirmTime',title: '确认收货时间', formatter: function (value) {
                    if (value==null){
                        return  "未收货";
                    }
                    return zero2one.dateFormat(value, 'Y-m-d H:i:s')
                }},
            {field: 'needTicket',title: '需要金卷'},
            {field: 'logisticsCompany',title: '物流公司'},
            {field: 'logisticsNo',title: '物流单号'},
            {field: 'presentTicket',title: '赠送金卷'},
            {field: 'presentExp',title: '赠送积分'},
            {field: 'cancelTime',title: '取消订单时间', formatter: function (value) {
                    if (value==null){
                        return  "无";
                    }
                    return zero2one.dateFormat(value, 'Y-m-d H:i:s')
                }},
            {field: 'goodNumber',title: '商品总数'},
            {field: 'memberId',title: '会员账号'},
            {field: 'id',title: '订单ID'},
            {field: 'note',title: '备注'},
        ];


        //进入主界面加载数据
        zero2one.datagrid("list_data", "/remote/StoreRecords/list",function (params) {
            return $.extend(zero2one.tableInitParam(params), zero2one.form2json("searchForm"));
        }, columns);

        //点击查询按钮重新加载页面数据
        $("#searchFormBtn").click(function () {
            $('#list_data').bootstrapTable('refresh');
        });


        //点击商品详情
        $("#watchBtn").click(function () {
            //获取选中行的数据
            var datas = $('#list_data').bootstrapTable('getSelections');
            //判断是否选中行数据，如果没有则提示
            if(datas.length == 1&&datas[0].goodItems!=''){
                var jsonObj =  JSON.parse(datas[0].goodItems);//json字符串转化成json对象
                var content='';
                for (let i = 0; i <jsonObj.length; i++) {
                    content+=
                        '<label style="font-size: x-large">☼商品名称：</label><label style="font-size: large">'+jsonObj[i].title+'</label></br>'
                        +'<label style="font-size: x-large">☼计数：</label><label style="font-size: large">'+jsonObj[i].count+'</label></br>'
                        +'<label style="font-size: x-large">☼价格：</label><label style="font-size: large">'+jsonObj[i].price+'元'+'</label></br>'
                        +'<label style="font-size: x-large">☼skuId：</label><label style="font-size: large">'+jsonObj[i].skuId+'</label></br>'
                        +'<label style="font-size: x-large">☼积分：</label><label style="font-size: large">'+jsonObj[i].giveJf+'</label></br>'
                        +'<label style="font-size: x-large">☼金券：</label><label style="font-size: large">'+jsonObj[i].needJq+'</label></br>'
                        +'<label style="font-size: x-large">☼规格：</label><label style="font-size: large">'+jsonObj[i].skuAttr+'</label></br>'
                        +'<label style="font-size: x-large">☼商店编号：</label><label style="font-size: large">'+jsonObj[i].storeId+'</label></br>'
                        +'<label style="font-size: x-large">☼库存：</label><label style="font-size: large">'+jsonObj[i].hasStock+'</label></br>'
                        +'<label style="font-size: x-large">☼产品编号：</label><label style="font-size: large">'+jsonObj[i].productId+'</label></br>'
                        +'<label style="font-size: x-large">☼店铺名称：</label><label style="font-size: large">'+jsonObj[i].storeName+'</label></br>'
                        +'<label style="font-size: x-large">☼商品总价格：</label><label style="font-size: large">'+jsonObj[i].totalPrice+'元'+'</label></br>'
                        +'<label style="font-size: x-large">☼优惠券：</label><label style="font-size: large">'+jsonObj[i].giveVoucher+'</label></br>'
                        +'<label style="font-size: x-large">☼订购货运：</label><label style="font-size: large">'+jsonObj[i].orderFreight+'</label></br>'
                        +'<label style="font-size: larger">图片:</label></br>'+"<img style='width: auto;height: auto;border-radius: 10%'  src='"+jsonObj[i].picture+"'/>"
                        +'<hr>';
                }
                $("#commodityMessage").html(content);
                //打开模态框
                $("#merchantShipmentModal").modal("show");

            }else{
                $.messager.alert("温馨提示", "请选择一条数据操作");
            }
        });


        //点击商品发货钮弹出模态框
        $("#merchantShipmentBtn").click(function () {
            //获取选中行的数据
            var datas = $('#list_data').bootstrapTable('getSelections');
            //判断是否选中行数据，如果没有则提示
            if(datas.length == 1){
                //填充表单
                $("#ShippedForm").formloader({data: datas[0]});
            }else{
                $.messager.alert("温馨提示", "请选择一条数据操作");
                return;
            }
            $("#ShippedModal").modal("show");
        });

        //保存按钮的点击事件
        $("#subtn").click(function () {
            zero2one.request("/remote/deliverGoods",$("#ShippedForm").serialize(),function (data) {
                if (data.success) {
                    window.location.reload();
                }else {
                    $.messager.alert("温馨提示", data.msg)
                }
            });
        });

        //导出商品数据按钮
        $("#generate-excel").click(function(){
            $.messager.confirm("提示", "您是否要导出所的数据?", function () {
                $("#searchForm").submit();
            });
        });


        //发票打印按钮
        $("#generate-invoice").click(function(){
            //获取选中行的数据
            var datas = $('#list_data').bootstrapTable('getSelections');
            // 判断是否选中行数据，如果没有则提示
            if(datas.length > 0){
                $.messager.confirm("温馨提示", "您确定要打印选中的数据发票吗?", function () {
                    //发送请求,执行批量删除
                    zero2one.request("/remote/getPrint",{"ids": zero2one.array2str(datas)},function (data) {
                        window.setTimeout("window.location.reload()",1000);//延迟1秒刷新
                    });
                })
            }else{
                $.messager.alert("温馨提示", "请选择一条或多条数据操作");

            }
        });


        //查看详细
        function seeDetails (orderid1,orderid2) {
            var orderId=orderid1+""+orderid2;
            $.post("/remote/fnygOrder/seeDetails", {"OrderId": orderId},function (data) {

                if (data != null) {
                    var content = '';
                    for (let i = 0; i <data.data.length; i++) {
                        console.log(data.data[i].refundPicture);

                        content +=
                            '<label style="font-size: x-large">☼商品名称：</label><label style="font-size: large">' + data.data[i].title + '</label></br>'
                            + '<label style="font-size: x-large">☼退款金额：</label><label style="font-size: large">' + data.data[i].refundPrice + '元' + '</label></br>'
                            // + '<label style="font-size: x-large">☼商品单价：</label><label style="font-size: large">' + data.data[i].goodsPrice + '元' + '</label></br>'
                            + '<label style="font-size: x-large">☼规格：</label><label style="font-size: large">' + data.data[i].skuAttr + '</label></br>'
                            + '<label style="font-size: x-large">☼产品skuId：</label><label style="font-size: large">' + data.data[i].skuId + '</label></br>'
                            + '<label style="font-size: x-large">☼退款数量：</label><label style="font-size: large">' + data.data[i].refundNum + '</label></br>'
                            + '<label style="font-size: x-large">☼商店名称：</label><label style="font-size: large">' + data.data[i].storeName + '</label></br>'
                            + '<label style="font-size: larger">商品图片:</label></br>' + "<img style='width: auto;height: auto;border-radius: 10%'  src='" + data.data[i].picture + "'/></br>"
                            + '<hr>';
                        if (data.data[i].refundPicture == 0) {
                            content += '<label style="font-size: larger">上传凭证:</label>' + "<label style=\"font-size: larger\">&emsp;无</label></br>";
                        } else {
                            content += '<label style="font-size: larger">上传凭证:</label></br>' + "<img style='width: auto;height: auto;border-radius: 10%'  src='" + data.data[i].refundPicture + "'/></br>";
                        }
                    }
                    $("#seeDetailsMessage").html(content);
                    //打开模态框
                    $("#seeDetailsModal").modal("show");

                } else {
                    $.messager.alert("温馨提示", data.msg)
                }
            },"json");
        }



</script>
</div>
</body>
</html>
